package com.ty.controller;

import com.ty.pojo.ItemCat;
import com.ty.service.ItemCatService;
import com.ty.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.List;

@RestController
@CrossOrigin
@EnableSwagger2
@RequestMapping("/itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;
    //查询菜单列表
    @GetMapping("/findItemCatList")
    public SysResult findItemCatList(ItemCat itemCat){
        List<ItemCat> itemCatList = itemCatService.findItemCatList(itemCat);
        return SysResult.success(itemCatList);
    }
    //新增菜单
    @PostMapping("/addItemCatList")
    @Transactional
    public SysResult addItemCatList(@RequestBody ItemCat itemCat){
        itemCatService.addItemCatList(itemCat);
        return SysResult.success();
    }
    //修改菜单
    @PutMapping("/updateItemCat")
    @Transactional //事物控制注解
    public SysResult updateItemCat(@RequestBody ItemCat itemCat){
        itemCatService.updateItemCat(itemCat);
        return SysResult.success();
    }
    //修改菜单状态,伪删除
    @PutMapping("/updatestate/{id}")
    @Transactional
    public SysResult updatestate(@PathVariable Integer id){
        itemCatService.updatestate(id);
        return SysResult.success();
    }
}
